package com.example.tass;

import cn.tass.SRJ1933.devices.inf.TassSignServerApi;
import cn.tass.exceptions.TAException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class TassApplication {

    public static void main(String[] args) {
        SpringApplication.run(TassApplication.class, args);
    }

    // 测试用接口
    @GetMapping(value = "/test")
    public String test() {
        return "hello";
    }
    
    // @Bean(value = "signServerApi")
    // public TassSignServerApi tassSignServerApi(){
    //     TassSignServerApi signServerApi = null;
    //     System.out.println("*********** 设备开始初始化 *********** ");
    //     try {
    //         //signServerApi = TassSignServerApi.init("config/cfg.ini");
    //         String config =
    //                 "{"
    //                         + "[LOGGER];"
    //                         + "logsw=error;logPath=./;"
    //                         + "[HOST 1];"
    //                         + "hsmModel=SRJ1933;"
    //                         + "linkNum=-15;"
    //                         + "host=192.168.2.192;"
    //                         + "port=9081;"
    //                         + "connTimeout=10;"
    //                         + "sysname=app;"
    //                         + "signkey=7g9C9nB7;"
    //                         + "}";
    //         signServerApi = TassSignServerApi.init(config);
    //         if (null == signServerApi) {
    //             System.err.println("设备初始化失败....");
    //         }
    //     } catch (TAException e) {
    //         System.err.println("设备初始化失败...");
    //         e.printStackTrace();
    //     }
    //     System.out.println("*********** 设备初始化成功 *********** ");
    //     return signServerApi;
    // }

    // 鼎链的签名验签服务器
    // qxz  6XDk63nT    需要认证密钥   需要密钥授权
    // testapp          不需要认证方式 不需要密钥授权
    // shg-testapp1     不需要认证方式 不需要密钥授权
    // shg-testapp2     不需要认证方式 需要密钥授权
    @Bean(value = "signServerApi")
    public TassSignServerApi tassSignServerApi(){
        TassSignServerApi signServerApi = null;
        System.out.println("*********** 设备开始初始化... *********** ");
        try {
            //signServerApi = TassSignServerApi.init("config/cfg.ini");
            String config =
                    "{"
                            + "[LOGGER];"
                            + "logsw=error;logPath=./;"
                            + "[HOST 1];"
                            + "hsmModel=SRJ1933;"
                            + "linkNum=-15;"
                            + "host=192.168.2.62;"
                            + "port=9081;"
                            + "connTimeout=10;"
                            + "sysname=shg-testapp3;"
                            + "signkey=x91FR71R;"
                            + "}";
            signServerApi = TassSignServerApi.init(config);
            if (null == signServerApi) {
                System.err.println("初始化失败....");
            }
        } catch (TAException e) {
            System.err.println("初始化失败...");
            e.printStackTrace();
        }
        return signServerApi;
    }

}
